using System;
using System.Collections.Generic;
using System.Text;
using Csla.Data;
using Csla;
using Active.Core.State;

namespace Active.Core
{
    /// <summary>
    /// The read only bill infomation.
    /// </summary>
    [Serializable()]
    public class BillInfo : ReadOnlyBase<BillInfo>
    {
        #region Business Methods

        // TODO: add your own fields, properties and methods
        private int _id;
        /// <summary>
        /// Gets the id.
        /// </summary>
        /// <value>The id.</value>
        public int Id
        {
            get { return _id; }
        }

        /// <summary>
        /// Override this method to return a unique identifying
        /// vlaue for this object.
        /// </summary>
        /// <returns></returns>
        /// <remarks>
        /// If you can not provide a unique identifying value, it
        /// is best if you can generate such a unique value (even
        /// temporarily). If you can not do that, then return
        /// <see langword="Nothing"/> and then manually override the
        /// <see cref="Equals"/>, <see cref="GetHashCode"/> and
        /// <see cref="ToString"/> methods in your business object.
        /// </remarks>
        protected override object GetIdValue()
        {
            return _id;
        }

        private string _number;
        /// <summary>
        /// Gets the number.
        /// </summary>
        /// <value>The number.</value>
        public string Number
        {
            get
            {
                return _number;
            }
        }

        private string _productName;
        /// <summary>
        /// Gets the name of the product.
        /// </summary>
        /// <value>The name of the product.</value>
        public string ProductName
        {
            get
            {
                return _productName;
            }
        }

        private DateTime _startDate;
        /// <summary>
        /// Gets the start date.
        /// </summary>
        /// <value>The start date.</value>
        public DateTime StartDate
        {
            get
            {
                return _startDate;
            }
        }

        private SmartDate _endDate;
        /// <summary>
        /// Gets the end date.
        /// </summary>
        /// <value>The end date.</value>
        public SmartDate EndDate
        {
            get
            {
                return _endDate;
            }
        }

        private StateValue _stateValue;
        /// <summary>
        /// Gets the state value.
        /// </summary>
        /// <value>The state value.</value>
        public StateValue StateValue
        {
            get
            {
                return _stateValue;
            }
        }

        #endregion

        #region Factory Methods

        internal static BillInfo GetBillInfo(SafeDataReader dr)
        {
            return new BillInfo(dr);
        }

        private BillInfo()
        { /* require use of factory methods */ }

        private BillInfo(SafeDataReader dr)
        {
            Fetch(dr);
        }

        #endregion

        #region Data Access

        private void Fetch(SafeDataReader dr)
        {
            _id = dr.GetInt32("Id");
            _endDate = dr.GetSmartDate("EndDate", false);
            _number = dr.GetString("Number");
            _productName = dr.GetString("Name");
            _startDate = dr.GetDateTime("StartDate");
            _stateValue = (StateValue)dr.GetInt32("StateValue");
        }

        #endregion
    }
}
